package cn.gong.movie.data;

import android.content.Context;
import cn.gong.movie.bean.Drama;
import cn.gong.movie.db.DbDrama;
import cn.gong.movie.db.DbMovie;
import cn.gong.movie.enums.DbTaskType;
import framework.config.TaskType;
import framework.database.callback.DBCallBack;
import framework.database.callback.DBDeal;

public class DataDrama extends DataBase {
	public static void setDrama(final Context context, final Drama drama, DBCallBack callBack) {
		deal(DbTaskType.dbTsSetDrama, callBack, new DBDeal() {

			@Override
			public Object deal(Object obj) {
				return new DbDrama().setDrama(context, drama);
			}
		});
	}

	public static void getFollowDramas(Context context, long followWatchTime, DBCallBack callBack) {
		getFollow(DbTaskType.dbTsGetFollowDramas, context, followWatchTime, callBack);
	}

	public static void getMoreFollowDramas(Context context, long followWatchTime, DBCallBack callBack) {
		getFollow(DbTaskType.dbTsGetMoreFollowDramas, context, followWatchTime, callBack);
	}

	private static void getFollow(DbTaskType type, final Context context, final long followWatchTime, DBCallBack callBack) {
		deal(type, callBack, new DBDeal() {

			@Override
			public Object deal(Object obj) {
				return new DbDrama().getFollowDramas(context, followWatchTime);
			}
		});
	}

	public static void getWantDramas(Context context, long lastIndex, DBCallBack callBack) {
		getWant(DbTaskType.dbTsGetWantDramas, context, lastIndex, callBack);
	}

	public static void getMoreWantDramas( Context context,  long lastIndex, DBCallBack callBack) {
		getWant(DbTaskType.dbTsGetMoreWantDramas, context, lastIndex, callBack);
	}

	private static void getWant(DbTaskType type, final Context context, final long lastIndex, DBCallBack callBack) {
		deal(type, callBack, new DBDeal() {

			@Override
			public Object deal(Object obj) {
				return new DbDrama().getWantDramas(context, lastIndex);
			}
		});
	}

	public static void getSeenDramas(Context context, long lastIndex, DBCallBack callBack) {
		getSeen(DbTaskType.dbTsGetSeenDramas, context, lastIndex, callBack);
	}

	public static void getMoreSeenDramas(Context context, long lastIndex, DBCallBack callBack) {
		getSeen(DbTaskType.dbTsGetMoreSeenDramas, context, lastIndex, callBack);
	}

	private static void getSeen(DbTaskType type, final Context context, final long lastIndex, DBCallBack callBack) {
		deal(type, callBack, new DBDeal() {

			@Override
			public Object deal(Object obj) {
				return new DbDrama().getSeenDramas(context, lastIndex);
			}
		});
	}

	public static void updateDrama(final Context context, final Drama drama, DBCallBack callBack) {
		deal(DbTaskType.dbTsUpdateDrama, callBack, new DBDeal() {

			@Override
			public Object deal(Object obj) {
				return new DbDrama().updateDrama(context, drama);
			}
		});
	}

	public static void deleteDrama(final Context context, final Drama drama, DBCallBack callBack) {
		deal(DbTaskType.dbTsDeleteDrama, callBack, new DBDeal() {

			@Override
			public Object deal(Object obj) {
				return new DbDrama().deleteDrama(context, drama);
			}
		});
	}

}
